# _*_ coding:utf-8 _*_
# @Time  : 2022.08.09
# @Author: zizlee
import json
import time

import requests
import urllib3
urllib3.disable_warnings()


def read_indexes():
    with open('波动率.json', 'r', encoding='utf8') as fp:
        indexes = json.load(fp)
    print('读取更新数量:', len(indexes))
    print('等待更新数量:', len(indexes))
    return indexes


def operate_request(index_id):
    # url = 'http://127.0.0.1:8000/v1/datalib/table/deleteManyWithDate/'
    url = 'https://210.13.218.130:9000/v1/datalib/table/deleteManyWithDate/'
    r = requests.delete(url, params={'indexId': index_id}, verify=False)
    print(r.json())


if __name__ == '__main__':
    indexes_list = read_indexes()
    symbols = {v['variety_en']: v['interval_symbol'] for v in indexes_list if v['flag'] == 'us_impliedvol'}
    zlid = {v['variety_en']: v['ZLID'] for v in indexes_list if v['flag'] == 'us_impliedvol'}
    price_rules = {v['variety_en']: v['price_rules'] for v in indexes_list if v['flag'] == 'us_impliedvol'}
    print(price_rules)
    for item in indexes_list:
        if not item.get('variety_en'):
            item['variety_en'] = item['wd_code'].split('.')[0]
            item['exchange'] = item['wd_code'].split('.')[1]
            item['interval_symbol'] = symbols.get(item['variety_en'], None)
            if item['interval_symbol'] is None:
                raise ValueError(f'interval_symbol{item["variety_en"]}不存在')
            item['direction'] = 'C'
            item['ZLID'] = zlid.get(item['variety_en'], None)
            if item['ZLID'] is None:
                raise ValueError('')
            item['price_rules'] = price_rules.get(item['variety_en'], None)
            if item['price_rules'] is None:
                raise ValueError('pp')
    with open('波动率2.json', 'w', encoding='utf8') as f:
        json.dump(indexes_list, f, indent=2, ensure_ascii=False)

